<?php
declare (strict_types = 1);

namespace app\subscribe;

use app\model\system\SystemAdmin;
use app\model\system\SystemLog;

/**
 * 管理员事件订阅类
 * Class SystemAdminSubscribe
 * @package app\subscribe
 */
class SystemAdminSubscribe
{
    /**
     * 管理员登录成功事件
     * @param $event
     */
    public function onSystemAdminLogin($event)
    {
        list($adminInfo) = $event;
        SystemAdmin::update(['last_ip' => app('request')->ip(), 'last_at' => date('Y-m-d H:i:s')], ['id' => $adminInfo['id']]);
    }

    /**
     * 添加管理员访问记录
     * @param $event
     */
    public function onAdminVisit($event)
    {
        list($adminInfo, $type) = $event;
        if (strtolower(app('request')->controller()) != 'index') SystemLog::adminVisit($adminInfo->id, $adminInfo->username, $type);
    }
}
